package com.cosina.game.tank.ai;

import java.util.LinkedList;
import java.util.Random;

import com.cosina.game.tank.ai.various.EnemyTankCommand;

class SimpleAI implements AI{
	public static Random random = new Random();
	private Object owner;
	
	public SimpleAI(Object owner){
		this.owner = owner;
	}
	
	private LinkedList<EnemyTankCommand> commands = new LinkedList<EnemyTankCommand>();
	private EnemyTankCommand lastCommand;
	
	private int timeMax = 3;
	@Override
	public void doNext(){
		if(commands.size()<=0){
			if(lastCommand != null && lastCommand.getClass().getName().indexOf("DoShot") < 0){
				if(random.nextInt(2) == 1){
					commands.add(lastCommand);
					for(int i=0; i<random.nextInt(timeMax);i++){
						commands.add(lastCommand);
					}
					return ;
				}
			}
			EnemyTankCommand etc = EnemyTankCommand.etcList.get(random.nextInt(EnemyTankCommand.etcList.size()));
			if(etc.getClass().getName().indexOf("DoShot")< 0){
				for(int i=0; i<random.nextInt(timeMax);i++){
					commands.add(etc);
				}
			}else{
				commands.add(etc);
			}
		}else{
			lastCommand = commands.poll();
			lastCommand.doBy(owner);
		}
	}
}
